package com.lz.football.module.compete
{
	import com.common.utils.Reflection;
	import com.lz.football.module.compete.item.TreasuryItem;
	
	import common.BaseView.BaseView;
	import common.comp.TabButtonBar;
	
	import flash.events.Event;
	import flash.text.TextField;
	
	import lz.controls.LButton;

	/**
	 *宝库 
	 * @author Administrator
	 * 
	 */	
	public class TreasuryView extends BaseView
	{
		/**
		 *选项卡 
		 */		
		private var buttonBar :TabButtonBar;
		private var _itemVec:Vector.<TreasuryItem>;
		/**
		 *说明  
		 */
		private var des:TextField;
		public function TreasuryView()
		{
			super();
		}
		/**
		 * 
		 * @param view
		 * 
		 */
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.compete.treasuryView");
			this.addChild(symbolSkin);
			symbolSkin.cacheAsBitmap = true;
			_windowBg = symbolSkin.treasuryBg;
			des = symbolSkin.des;
			isDrag = true;
			isCloseBtn = true;
			_viewHeight = symbolSkin.height;
			_viewWidth  = symbolSkin.width;
			moveClose(_viewWidth - 30,5);
			//选项bar 初始化
			buttonBar = new TabButtonBar();
			var i :int = 0;
			var lbtn :LButton;
			var lbtns :Array = [];
			for(;i<=2;i++)
			{
				lbtn = new LButton(symbolSkin["skin_" + i]);
				lbtn.enable = true;
				lbtns.push(lbtn);
			}
			buttonBar.setButtons(lbtns);
			buttonBar.selectTabButton(lbtns[0]);
			initItem();
			onResizeHandler();
			addEvtListener();
			onTabChangeHandler();
		}
		/**
		 *初始化item 
		 * 
		 */
		private function initItem():void
		{
			_itemVec = new Vector.<TreasuryItem>();
			var item:TreasuryItem;
			for(var i:int = 0;i < 4;i++)
			{
				item = new TreasuryItem();
				item.initUI();
				item.x = (item.width + 3) * i + 16;
				item.y = 80;
				_itemVec.push(item);
				this.addChild(item);
			}
		}
		override public function addEvtListener():void
		{
			buttonBar.addEventListener(Event.CHANGE,onTabChangeHandler);
		}
		/**
		 *选项卡改变 
		 * @param e
		 * 
		 */		
		private function onTabChangeHandler(e :Event = null):void
		{
			changeDate(buttonBar.selectType);
		}
		/**
		 * 
		 * 
		 */
		private function changeDate($type:int):void
		{
			var arr:Array;
			switch($type)
			{
				case 0:
					arr = [[14,5],[7,5],[20,5],[1898,1]];
//					des.text = "以上道具只有国王才可以购买以及使用！";
					break;
				case 1:
					arr = [[12,5],[5,5],[19,5],[900,1]];
//					des.text = "只有在国家挑战赛中排名进前30的玩家可以使用！";
					break;
				case 2:
					arr = [[31,4],[18,3],[32,2],[18,5]];
//					des.text = "只有在国家挑战赛中排名进前100的玩家可以使用！";
					break;
			}
			var len:int = arr.length;
			for(var i:int = 0;i < len;i++)
			{
				_itemVec[i].setdata(arr[i]);
				_itemVec[i].tyep = $type + 1;
			}
		}
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			buttonBar.removeEventListener(Event.CHANGE,onTabChangeHandler);
		}
		override public function destroyView():void
		{
			removeEvtListener();
			while(_itemVec.length)
			{
				_itemVec.pop().destroyView();
			}
			_itemVec = null;
			if(this.parent)this.parent.removeChild(this);
			buttonBar.destroyView();
			buttonBar = null;
		}
	}
}